package com.smartstate.autoMaticControl.controller;

import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import com.smartstate.autoMaticControl.entity.Dedusting;
import com.smartstate.autoMaticControl.entity.Dehumidifier;
import com.smartstate.autoMaticControl.entity.Dictionary;
import com.smartstate.autoMaticControl.service.DictionaryService;
import io.swagger.annotations.Api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@RestController
@Slf4j
@Api(tags = {"字典表"})
@RequestMapping("/dictionary")
public class DictionaryController {

    @Resource
    private DictionaryService dictionaryService;

    private static String[] arr={"正常","异常"};

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/add")
    public boolean dictionaryAdd(@RequestParam("fieldName") String fieldName,@RequestParam("name") String name){
        Dictionary dictionary = new Dictionary();
        dictionary.setFieldName(fieldName);
        dictionary.setName(name);
        dictionaryService.add(dictionary);
        return true;
    }

    @GetMapping("/getAll")
    public List<Dictionary> getAll(){
        return dictionaryService.getAll();
    }

    @GetMapping("/addAll")
    public boolean addAll(){
        ArrayList<Dedusting> list = new ArrayList<>();
        for (int i = 0; i < 51; i++) {
            Dedusting dedusting = new Dedusting();
            dedusting.setDeviceId("CSJ00"+i);
            dedusting.setNeGaTive(new Random().nextInt(50));
            dedusting.setSPraying(new Random().nextInt(50));
            dedusting.setMotorSpeed(new Random().nextInt(50));
            dedusting.setType(arr[new Random().nextInt(arr.length)]);
            Map<String, Object> map = BeanUtils.beanToMap(dedusting);
            redisTemplate.opsForHash().putAll("Dedusting:CSJ00"+i,map);
        }
        return true;
    }
    @GetMapping("/addDehumidifierAll")
    public boolean addDehumidifierAll(){
        ArrayList<Dedusting> list = new ArrayList<>();
        for (int i = 0; i < 51; i++) {
            Dehumidifier dehumidifier = new Dehumidifier();
            dehumidifier.setId(UUID.randomUUID().toString());
            dehumidifier.setDeviceId("CCJ00"+i);
            dehumidifier.setReturnAirDewPoint(new Random().nextInt(50));
            dehumidifier.setReturnAirTemperature(new Random().nextInt(50));
            dehumidifier.setSupplyAirDewPoint(new Random().nextInt(50));
            dehumidifier.setSupplyAirTemperature(new Random().nextInt(50));
            dehumidifier.setRoomDewPoint(new Random().nextInt(50));
            dehumidifier.setRoomTemperature(new Random().nextInt(50));
            dehumidifier.setType(arr[new Random().nextInt(arr.length)]);
            Map<String, Object> map = BeanUtils.beanToMap(dehumidifier);
            redisTemplate.opsForHash().putAll("Dehumidifier:CCJ"+i, map);
        }
        return true;
    }

}
